<%-- 
    Document   : TestQueryByPool
    Created on : 2010/1/28, 上午 09:20:27
    Author     : gmlin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8" import="javax.naming.*,javax.sql.*,java.sql.*,java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>TestQueryByPool</title>
    </head>
    <body>
        <%
            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;

            try {
                Context ctx = new InitialContext();
                Context envContext = (Context) ctx.lookup("java:/comp/env");
                DataSource ds = (DataSource) envContext.lookup("MYSQL_GM");
                conn = ds.getConnection();

                stmt = conn.createStatement();
                rs = stmt.executeQuery("select count(*) from school_ext where emp_name like '%林%'");

                out.println("測試成功，以下為測試資料<br/>");

                while (rs.next()) {
                    for (int j = 0; j < rs.getMetaData().getColumnCount(); j++) {
                        out.print(rs.getObject(j + 1));
                        out.print("\t");
                    }
                    out.println();
                }
            }
            catch (Exception ex) {
                ex.printStackTrace();
                //System.out.println(this.toString().substring(this.toString().lastIndexOf('.') + 1,this.toString().lastIndexOf('@')) + ".java" +  " (getConn) Exception --> " + ex.toString());
            }
            finally{
                if (rs != null) {
                    try {
                        rs.close();
                        rs = null;
                    } catch (Exception se) {
                        se.printStackTrace();
                    }
                } //釋放沒用的ResultSet
                if(stmt!=null){
                    stmt.close();
                    stmt=null;
                }
                if (conn != null) {
                    conn.close();
                    conn=null;
                }
            }
        %>
    </body>
</html>
